# -*- coding: utf-8 -*-
"""
Created on Wed Nov 01 14:06:00 2017

@author: liuke
"""

import SocketServer
import os
from threading import Thread
from time import ctime

HOST = ""
POST = 1314
BUFFSIZE=1024

class MyTcpHandler(SocketServer.BaseRequestHandler):        
    def handle(self):
        print 'got connection from: ',self.client_address
        while 1:
            self.data = self.request.recv(BUFFSIZE).strip()
            if not self.data:
                continue
            self.request.sendall(self.data)
            STOP_CHAR = (self.data.decode('utf8').upper()=='QUIT')
            if STOP_CHAR:
                print self.client_address,' quit!'
                break
            print ctime(),': ',self.data
        
my_server = SocketServer.ThreadingTCPServer((HOST,POST), MyTcpHandler)
print my_server.server_address,' runing'
#my_server.serve_forever()
t = Thread(target=my_server.serve_forever())
#t.start()
print 'hahahahahahaahah '
